package com.ln.lnzw.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.google.gson.Gson;
import com.ln.lnzw.R;
import com.ln.lnzw.activity.HandleaffairsServiceSecondaryKindActivity;
import com.ln.lnzw.app.AppConstant;
import com.ln.lnzw.base.BaseFragment;
import com.ln.lnzw.bean.ImplementationSubjectBean;
import com.ln.lnzw.net.HttpMethodString;
import com.ln.lnzw.utils.ImageUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by wuwei on 2018/4/16.
 * 职权类型
 */

public class TypeOfAuthorityFragment extends BaseFragment {
    @BindView(R.id.iv_image1)
    ImageView ivImage1;
    @BindView(R.id.iv_image2)
    ImageView ivImage2;
    Unbinder unbinder;
    @BindView(R.id.iv_image3)
    ImageView ivImage3;
    @BindView(R.id.iv_image4)
    ImageView ivImage4;
    @BindView(R.id.iv_image5)
    ImageView ivImage5;
    @BindView(R.id.iv_image6)
    ImageView ivImage6;
    @BindView(R.id.iv_image7)
    ImageView ivImage7;
    @BindView(R.id.tv_xingzhengxuke)
    TextView tvXingzhengxuke;
    @BindView(R.id.rl_xingzhengxuke)
    RelativeLayout rlXingzhengxuke;
    @BindView(R.id.tv_xingzhengzhengshou)
    TextView tvXingzhengzhengshou;
    @BindView(R.id.ll_xingzhengzhengshou)
    LinearLayout llXingzhengzhengshou;
    @BindView(R.id.tv_xingzhengjifu)
    TextView tvXingzhengjifu;
    @BindView(R.id.rl_xingzhengjifu)
    RelativeLayout rlXingzhengjifu;
    @BindView(R.id.tv_gonggongfuwu)
    TextView tvGonggongfuwu;
    @BindView(R.id.rl_gonggongfuwu)
    RelativeLayout rlGonggongfuwu;
    @BindView(R.id.tv_qitaquanli)
    TextView tvQitaquanli;
    @BindView(R.id.rl_qitaquanli)
    RelativeLayout rlQitaquanli;
    @BindView(R.id.tv_neibushenpi)
    TextView tvNeibushenpi;
    @BindView(R.id.rl_neibushenpi)
    RelativeLayout rlNeibushenpi;
    @BindView(R.id.tv_xingzhengqueren)
    TextView tvXingzhengqueren;
    @BindView(R.id.rl_xingzhengqueren)
    RelativeLayout rlXingzhengqueren;
    @BindView(R.id.rl_layout)
    RelativeLayout rlLayout;
    private List<ImplementationSubjectBean.ListDatasBean> mlist = new ArrayList<>();
    private Bundle b;
//    public static String  TYPEOFAUTHRITY = "type_of_authority";
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.type_of_authority_activity, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ImageUtil.suitDisplay2(ivImage1, 5, 3);
        ImageUtil.suitDisplay2(ivImage2, 5, 3);
        ImageUtil.suitDisplay2(ivImage3, 5, 3);
        ImageUtil.suitDisplay2(ivImage4, 5, 3);
        ImageUtil.suitDisplay2(ivImage5, 5, 3);
        ImageUtil.suitDisplay2(ivImage6, 5, 3);
        ImageUtil.suitDisplay1(ivImage7, 449, 224);
        initData();

    }

    private void initData() {
//        HttpMethodString.getInstance().info.getStringData(AppConstant.TERMS_REFERENCE_URL)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Observer<String>() {
//                    @Override
//                    public void onSubscribe(Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(String s) {
//                        Log.i("123", "onNext: " + s);
                        Gson gson = new Gson();
                        ImplementationSubjectBean implementationSubjectBean = gson.fromJson(activity.spUtils.getString(AppConstant.TYPEOFAUTHRITY), ImplementationSubjectBean.class);
                        if (mlist != null || !mlist.isEmpty()) {
                            mlist.clear();
                        }
                        mlist.addAll(implementationSubjectBean.getList_datas());
//                        activity.spUtils.put(TYPEOFAUTHRITY,s);
//                    }

//                    @Override
//                    public void onError(Throwable e) {
//
//                    }

//                    @Override
//                    public void onComplete() {
                        setName();
//                    }
//                });
    }

    private void setName() {
        tvXingzhengxuke.setText(mlist.get(0).getCname());
        tvXingzhengzhengshou.setText(mlist.get(1).getCname());
        tvXingzhengjifu.setText(mlist.get(2).getCname());
        tvXingzhengqueren.setText(mlist.get(3).getCname());
        tvGonggongfuwu.setText(mlist.get(4).getCname());
        tvQitaquanli.setText(mlist.get(5).getCname());
        tvNeibushenpi.setText(mlist.get(6).getCname());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.rl_xingzhengxuke, R.id.ll_xingzhengzhengshou, R.id.rl_xingzhengjifu, R.id.rl_xingzhengqueren, R.id.rl_gonggongfuwu, R.id.rl_qitaquanli, R.id.rl_neibushenpi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_xingzhengxuke:
                b = new Bundle();
                b.putString("cDesc", mlist.get(0).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.ll_xingzhengzhengshou:
                b = new Bundle();
                b.putString("cDesc", mlist.get(1).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.rl_xingzhengjifu:
                b = new Bundle();
                b.putString("cDesc", mlist.get(2).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.rl_xingzhengqueren:
                b = new Bundle();
                b.putString("cDesc", mlist.get(3).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.rl_gonggongfuwu:
                b = new Bundle();
                b.putString("cDesc", mlist.get(4).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.rl_qitaquanli:
                b = new Bundle();
                b.putString("cDesc", mlist.get(5).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
            case R.id.rl_neibushenpi:
                b = new Bundle();
                b.putString("cDesc", mlist.get(6).getCdesc());
                ActivityUtils.startActivity(b, activity, HandleaffairsServiceSecondaryKindActivity.class);
                break;
        }
    }

}
